package com.igeek.compus.test.seller.controller;

import com.github.pagehelper.PageInfo;
import com.igeek.compus.test.seller.entity.Seller;
import com.igeek.compus.test.seller.service.SellerService;
import com.igeek.compus.test.system.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("seller")
public class SellerController {

    @Autowired
    private SellerService sellerService;

    /**
     * 获得卖家列表
     *
     * @param seller
     * @return
     */
    @RequestMapping("list.do")
    @ResponseBody
    public Map list(Seller seller) {
        Map<String, Object> result = new HashMap<>();

        try {

            PageInfo<Seller> pageInfo = new PageInfo<>(sellerService.getSellerListByPage(seller));

            result.put(Constants.RETDATA, pageInfo.getList());
            result.put(Constants.COUNT, pageInfo.getTotal());

            result.put(Constants.RETCODE, Constants.SUCCESS_CODE);
            result.put(Constants.RETMSG, Constants.SUCCESS_MSG);
        } catch (Exception e) {
            e.printStackTrace();
            result.put(Constants.RETCODE, Constants.SUCCESS_CODE);
            result.put(Constants.RETMSG, Constants.ERROR_MSG);
        }

        return result;
    }
}
